package com.guw.TestThread;

import java.util.concurrent.CopyOnWriteArrayList;

//测试JUC安全类型的集合
public class TestJUC {
    public static void main(String[] args) {
        //测试结果一直是10000,证明CopyOnWriteArreyList方法是线程安全的
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
        new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                list.add(Thread.currentThread().getName());
            }
        }).start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
